<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产品编号" prop="productNo">
        <el-input
          v-model="queryParams.productNo"
          placeholder="请输入产品编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="productList" @current-change="handleCurrentChange" highlight-current-row>
      <el-table-column label="产品编号" align="center" prop="productNo" />
      <el-table-column label="产品名称" align="center" prop="productName" />
    </el-table>
    <div>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { listProduct } from "@/api/trace/product";

export default {
  name: "ProductSelect",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      //选中的数据
      currentRow: null,
      // 总条数
      total: 0,
      // 产品信息表格数据
      productList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productNo: null,
        productName: null,
        productLand: null,
        productType: null,
        productEstimateCount: null,
        productSize: null,
        productWeight: null,
        productGuaranteePeriod: null,
        productStorage: null,
        productPermit: null,
        productPic: null,
        productPerson: null,
        productPersonPhone: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询产品信息列表 */
    getList() {
      this.loading = true;
      listProduct(this.queryParams).then(response => {
        this.productList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        productId: null,
        productNo: null,
        productName: null,
        productLand: null,
        productType: null,
        productEstimateCount: null,
        productSize: null,
        productWeight: null,
        productGuaranteePeriod: null,
        productStorage: null,
        productPermit: null,
        productPic: null,
        productPerson: null,
        productPersonPhone: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 选中数据
    handleCurrentChange(val) {
      this.$emit("productSelect",val)
    }
  }
};
</script>